package com.hpu.service;

import android.content.Context;
import android.os.Handler;
import android.util.Log;

import com.hpu.callback.ImageCallback;
import com.hpu.callback.ImagePathCallback;
import com.hpu.constants.ShareConstants;
import com.hpu.constants.UrlConstants;
import com.hpu.interceptor.ReceivedCookieInterceptor;
import com.hpu.tools.InternetTools;
import com.hpu.tools.OkHttpTools;
import com.hpu.tools.ShareTools;

/**
 * 期末成绩业务类
 * @author Administrator
 *
 */
public class ImageService{

	private Handler handler;
	
	private Context context;
	
	public ImageService(Handler handler,Context context) {
		this.handler=handler;
		this.context=context;
	}

	public void getImagePath() {
		if(InternetTools.statusInternet(context)==InternetTools.NO_INTERNET)
		{}
		else
		OkHttpTools.getByCookie(new ReceivedCookieInterceptor(context),UrlConstants.INTERFACE_GET_IMAGEPATH,
				ShareTools.get(context, ShareConstants.STORE_LOGINCOOKIE, "").toString(), 
				new ImagePathCallback(handler));
	}
	
	public void getImage(String url) {
		Log.i("ImageService", "url:"+url);
		if(!url.startsWith("http")){
			url="http://"+url;
		}
		if(InternetTools.statusInternet(context)==InternetTools.NO_INTERNET)
		{}
		else
		OkHttpTools.get(new ReceivedCookieInterceptor(context),url,
				new ImageCallback(handler));
	}

}
